#!/usr/bin/env groovy
@GrabResolver(name = 'alipaypllus', root = 'http://mvn.dev.alipayplus.alipay.net/nexus/content/repositories/Core-Release')
@Grab(group = 'com.alibaba.tools', module = 'myenv-all', version = '1.0.3', changing = 'true')

import com.alibaba.tools.myenv.containers.*

// start local mysql server with database name and domain name being set
MyMYSQL57 mysql = MyMYSQL57.newInstance()
        .withDBUser("admin")
        .withDBPassword("admin")
        .withDBName("myenv")
        .withServiceExposedPort(3316)
        .create();
println "Service Information:\nmysql server(${mysql.bashExec("mysql --version")}) started, connect to '${mysql.getConnectString()}'\n"

// create testing table
mysql.executeSql """\
CREATE TABLE tbl_employee (
    id int auto_increment primary key,
    first_name varchar(128) NOT null,
    last_name varchar(128) NOT null,
    address varchar(256),
    email varchar(128),
    department_id int default 9,
    joining_date date 
);"""

// insert sample data
mysql.executeSql """\
INSERT INTO tbl_employee(first_name,last_name,address,email,department_id,joining_date) VALUES 
("Dixit","Upadhyay","Cecelia Havens, 456 White Finch St.","xuz@abc.com",9,current_date()),
("Bharti","Tilyed","Kenner Group Inc.","p@gmail.com",2,current_date()),
("Priya", "Vivek","85 Bradford Lane, Vincentown, NJ 08120","tom@yahoo.com",4,current_date());"""

// perform database select query
String output = mysql.executeSelect "SELECT * FROM tbl_employee;"
println "Select Result:\n${output}\n"

// describe all environment information
println "Environment Information:\n${MyEnvironment.LOCAL.describe()}\n"

// wait for manual terminate process exit
Thread.currentThread().join();